package com.lbb.utils

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter


class FragmentAdapter : FragmentPagerAdapter {
    private val fragments: List<Fragment>
    private var titles: List<String>? = null

    constructor(fm: FragmentManager, fragments: List<Fragment>) : super(
        fm,
        BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT
    ) {
        this.fragments = fragments
    }

    constructor(fm: FragmentManager, fragments: List<Fragment>, titles: List<String>) : super(
        fm,
        BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT
    ) {
        this.fragments = fragments
        this.titles = titles
    }

    override fun getItem(position: Int): Fragment {
        return fragments[position]
    }

    override fun getCount(): Int {
        return fragments.size
    }

    override fun getPageTitle(position: Int): CharSequence? {
        titles?.let {
            return it[position]
        }
        return super.getPageTitle(position)
    }
}